package ext.tianma.bom.workflow;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Properties;

import ext.tianma.version.ComToolUtil;


/**Description:单例模式，绝对防止多实例化，提高速度和增强可读性、易维护性
 * @author    :  YangWen
 * @create at :  2013-9-29   上午7:33:58
 */
public enum SingletonBOM {
	
	INSTANCE;
	public static SingletonBOM getInstance() {
		return INSTANCE;
	}
	
	private String getPath(){
		return SingletonBOM.class.getResource("").getPath()+"bom.properties";	
	}
	
	
	/**从配置文件里获得指定的属性值
	 * @param properties  指定的属性值
	 * @return
	 * @throws Exception
	 */
	public  ArrayList<String> getBOMPropertyValue(ArrayList<String> properties) throws Exception {
				   
		if(properties==null||properties.size()==0)
			return null;
		
	    InputStream is = new FileInputStream(getPath());
		Properties p = new Properties();
		p.load(is);
		is.close();
		
		ArrayList<String> result = new ArrayList<String>();
		for(int i=0;i<properties.size();i++)
		   result.add(p.getProperty(properties.get(i)).toString().trim());
		
		return result;		
	}
	
	/**从配置文件里获得指定的属性值
	 * @param properties  指定的属性值
	 * @return
	 * @throws Exception
	 */
	public  String getBOMPropertyValue(String property) throws Exception {
				   
		if(ComToolUtil.isEmpty(property))
			return "";
		
	    InputStream is = new FileInputStream(getPath());
		Properties p = new Properties();
		p.load(is);
		is.close();
		
		return p.getProperty(property).toString().trim();
	}
	
	public String getRawMaterial() {	
		String result = null;
		try {
			result =  getBOMPropertyValue("WTPart")+"|"+getBOMPropertyValue("RawMaterial");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return result;
	}
	
	public String getSemiFinishedGood() {	
		String result = null;
		try {
			result =  getBOMPropertyValue("WTPart")+"|"+getBOMPropertyValue("SemiFinishedGood");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return result;
	}
	
	public String getFinishedGood() {	
		String result = null;
		try {
			result =  getBOMPropertyValue("WTPart")+"|"+getBOMPropertyValue("FinishedGood");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return result;
	}
	
	public String getTwoLevelMaterial() {	
		String result = null;
		try {
			result =  getBOMPropertyValue("WTPart")+"|"+getBOMPropertyValue("TwoLevelMaterial");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return result;
	}
	
	public String getDrawingDoc() {	
		String result = null;
		try {
			result =  getBOMPropertyValue("WTPart")+"|"+getBOMPropertyValue("DrawingDoc");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return result;
	}
	
	
	
	

	

}
